# ======================================================
# 			UNIVERSIDADE FEDERAL DE PERNANMBUCO
#
# MAKEFILE FOR ADAPTATION PROJECT
# Author: 	R. Soares, B. Silva, G. Caminha
# Created:	2008-2012
# ======================================================

# Rogerio: rogerio.soaress@ufpe.br

# flag for compilation
# ====================
#
CXXFLAGS=-DPARALLEL -g -Wall -D__ADAPTATION_DEBUG__ -D__ERROR_ANALYSIS_DEBUG__
APP_DIR=$(HOME)/applications
PROJ_DIR=$(HOME)/Downloads/PROJETO/versao_nova_rogerio_test
GMSH_DIR=$(HOME)/Downloads/PROJETO/GMSH27

# compilers
# =========
CXX=mpicxx

# paths for headers
# =================
INCLUDES=-I$(APP_DIR)/FMDB-2011/include \
	-I$(APP_DIR)/autopack/include \
	-I$(PROJ_DIR)/include \
	-I$(PROJ_DIR)/src/adaptation \
	-I$(PROJ_DIR)/src/adaptation/adaptative-remeshing \
	-I$(PROJ_DIR)/src/adaptation/h-refinement \
	-I$(PROJ_DIR)/src/elliptic \
	-I$(PROJ_DIR)/src/error-analysis \
	-I$(PROJ_DIR)/src/high-order \
	-I$(PROJ_DIR)/src/hyperbolic \
	-I$(PROJ_DIR)/src/interpolation \
	-I$(PROJ_DIR)/src/pre-processor \
	-I$(PROJ_DIR)/src/SIMULATION_core \
	-I$(PROJ_DIR)/src/tools \
	-I$(GMSH_DIR)/include \
	-I$(GMSH_DIR)/include/Common \
	-I$(GMSH_DIR)/include/Geo \
	-I$(GMSH_DIR)/include/Numeric \
	-I$(GMSH_DIR)/include/Mesh \
	-I$(GMSH_DIR)/include/Parser \
	-I$(GMSH_DIR)/include/Plugin \
	-I$(GMSH_DIR)/include/Post \
	-I$(GMSH_DIR)/include/Mesh \
	-I$(GMSH_DIR)/include/build/Common

# paths for libraries
# ===================
LIBS=-L$(APP_DIR)/FMDB-2011/lib -lFMDB-O \
	-L$(APP_DIR)/ParMetis-3.1/lib -lparmetis -lmetis \
	-L$(APP_DIR)/autopack/lib -lautopack-O \
	-L$(GMSH_DIR)/lib -lGmsh


# path for where the objects must be put
# ======================================
OBJ_DIR=$(PROJ_DIR)/objs

# paths for each program source part
# ==================================
SRC_DIR1=$(PROJ_DIR)/src
SRC_DIR2=$(PROJ_DIR)/src/adaptation
SRC_DIR3=$(PROJ_DIR)/src/elliptic
SRC_DIR4=$(PROJ_DIR)/src/error-analysis
SRC_DIR5=$(PROJ_DIR)/src/high-order
SRC_DIR6=$(PROJ_DIR)/src/hyperbolic
SRC_DIR7=$(PROJ_DIR)/src/interpolation
SRC_DIR8=$(PROJ_DIR)/src/pre-processor
SRC_DIR9=$(PROJ_DIR)/src/SIMULATION_core
SRC_DIR10=$(PROJ_DIR)/src/tools
SRC_DIR11=$(PROJ_DIR)/src/adaptation/adaptative-remeshing
SRC_DIR12=$(PROJ_DIR)/src/adaptation/h-refinement


OBJECTS=$(OBJ_DIR)/main.o $(OBJ_DIR)/auxiliar.o $(OBJ_DIR)/SimulatorParameters.o \
	$(OBJ_DIR)/SIMULATION_core.o $(OBJ_DIR)/Exception.o $(OBJ_DIR)/exportVTK.o \
	$(OBJ_DIR)/PhysicPropData.o $(OBJ_DIR)/GeomData.o $(OBJ_DIR)/LoadSimulatorParameters.o \
	$(OBJ_DIR)/MeshData.o $(OBJ_DIR)/EBFV1_elliptic.o $(OBJ_DIR)/set_SOE.o \
	$(OBJ_DIR)/load_EBFV1_PreProcessorData.o $(OBJ_DIR)/EBFV1_E.o $(OBJ_DIR)/EBFV1_G.o \
	$(OBJ_DIR)/EBFV1_F_omega.o $(OBJ_DIR)/EBFV1_F_gamma.o $(OBJ_DIR)/EBFV1_pressure_gradient.o \
	$(OBJ_DIR)/EBFV1_hyperbolic.o $(OBJ_DIR)/EBFV1_hyperbolic-adaptative.o \
	$(OBJ_DIR)/EBFV1_velocityField.o $(OBJ_DIR)/EBFV1_advectiveTerm.o \
	$(OBJ_DIR)/explicit-advance.o $(OBJ_DIR)/OilProductionManagement.o \
	$(OBJ_DIR)/HighOrderApproximation.o $(OBJ_DIR)/SaturationGradient.o \
	$(OBJ_DIR)/SL__Woodfield.o $(OBJ_DIR)/SL__MUSCL.o $(OBJ_DIR)/Restart.o \
    $(OBJ_DIR)/CalculateDegreeOfRefinement_2D.o $(OBJ_DIR)/AdaptativeRemeshing.o \
    $(OBJ_DIR)/H_Refinement.o $(OBJ_DIR)/H_Refinement_2D.o \
    $(OBJ_DIR)/CalculateElementsError_2D.o $(OBJ_DIR)/CalculateGlobalError.o \
    $(OBJ_DIR)/ErrorAnalysis.o $(OBJ_DIR)/ErrorAnalysisAuxiliar.o $(OBJ_DIR)/CalculateSmoothGradientNorm_2D.o \
	$(OBJ_DIR)/Calculate-Cij-parallel.o \
	$(OBJ_DIR)/Calculate-Vi-parallel.o $(OBJ_DIR)/EBFV1__pre-processors.o \
	$(OBJ_DIR)/EBFV1-2D-pp.o $(OBJ_DIR)/EBFV1-3D-pp.o \
	$(OBJ_DIR)/setCorrectNumberOfRemoteCopies.o $(OBJ_DIR)/validate-EBFV1.o \
    $(OBJ_DIR)/LoadMeshAdaptationParameters.o $(OBJ_DIR)/SIMULATION_core__solvers.o \
    $(OBJ_DIR)/MeshRegularization.o $(OBJ_DIR)/SpecialElements_2D.o \
    $(OBJ_DIR)/UnevenElements.o $(OBJ_DIR)/EBFV1__DefectCorrectionSolver.o $(OBJ_DIR)/EBFV1__MatrixFreeSolver.o \
    $(OBJ_DIR)/EBFV1_preprocessor.o $(OBJ_DIR)/testingAdaptation.o $(OBJ_DIR)/IhR_main.o  $(OBJ_DIR)/IAR_main.o \
	$(OBJ_DIR)/IAR_calculate.o \
	$(OBJ_DIR)/FileManager.o $(OBJ_DIR)/FileManagerFunctions.o \
	$(OBJ_DIR)/MRE.o $(OBJ_DIR)/Rebuilder3.o $(OBJ_DIR)/ErrorEstimator.o	


# how the executable will be named
# ================================
EXEC=PADMEC_AMR.exe

## top taget
all:	$(EXEC)
include ${PETSC_DIR}/bmake/common/base

$(EXEC):	$(OBJECTS) chkopts
	@echo "Linking objects..."
	@-$(CXX) -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c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)

$(OBJ_DIR)/%.o:	$(SRC_DIR11)/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES)  -c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)

$(OBJ_DIR)/%.o:	$(SRC_DIR12)/%.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES)  -c $< ${PETSC_INCLUDE}
	@mv *.o $(OBJ_DIR)

rebuild:
	@rm -f $(OBJ_DIR)/*.o $(EXEC)
	@echo "Limpeza concluida"
	@make
